import { TestFile } from '../../src/components/CustomSandpack';

# Date

### .toBeDate()

Use `.toBeDate` when checking if a value is a `Date`.

<TestFile name="toBeDate">
  {`test('passes when value is a date', () => {
  expect(new Date()).toBeDate();
  expect('01/01/2018').not.toBeDate();
  expect(new Date('01/01/2018')).toBeDate();
  expect(undefined).not.toBeDate();
});`}
</TestFile>

### .toBeValidDate()

Use `.toBeValidDate` when checking if a given `Date` object is valid.

<TestFile name="toBeValidDate">
  {`test('passes when Date is valid', () => {
  expect(new Date()).toBeValidDate();
  expect('01/01/2018').not.toBeValidDate();
  expect(new Date('01/01/2018')).toBeValidDate();
  expect(new Date('01/90/2018')).not.toBeValidDate();
  expect(undefined).not.toBeValidDate();
});`}
</TestFile>

### .toBeAfter(date)

Use `.toBeAfter` when checking if a date occurs after `date`.

<TestFile name="toBeAfter">
  {`test('passes when input is after date', () => {
  expect(new Date('01/01/2019')).toBeAfter(new Date('01/01/2018'));
  expect('01/01/2018').not.toBeAfter(new Date('01/01/2019'));
});`}
</TestFile>

### .toBeBefore(date)

Use `.toBeBefore` when checking if a date occurs before `date`.

<TestFile name="toBeBefore">
  {`test('passes when input is before date', () => {
  expect(new Date('01/01/2018')).toBeBefore(new Date('01/01/2019'));
  expect('01/01/2019').not.toBeBefore(new Date('01/01/2018'));
});`}
</TestFile>

### .toBeAfterOrEqualTo(date)

Use `.toBeAfterOrEqualTo` when checking if a date equals to or occurs after `date`.

<TestFile name="toBeAfterOrEqualTo">
  {`test('passes when input is equal to or after date', () => {
  expect(new Date('01/01/2019')).toBeAfterOrEqualTo(new Date('01/01/2018'));
  expect(new Date('01/01/2019')).toBeAfterOrEqualTo(new Date('01/01/2019'));
  expect('01/01/2018').not.toBeAfterOrEqualTo(new Date('01/01/2019'));
});`}
</TestFile>

### .toBeBeforeOrEqualTo(date)

Use `.toBeBeforeOrEqualTo` when checking if a date equals to or occurs before `date`.

<TestFile name="toBeBeforeOrEqualTo">
  {`test('passes when input is equal to or before date', () => {
  expect(new Date('01/01/2018')).toBeBeforeOrEqualTo(new Date('01/01/2019'));
  expect(new Date('01/01/2018')).toBeBeforeOrEqualTo(new Date('01/01/2018'));
  expect('01/01/2019').not.toBeBeforeOrEqualTo(new Date('01/01/2018'));
});`}
</TestFile>

### .toBeBetween(startDate, endDate)

Use `.toBeBetween` when checking if a date equals or occurs after `startDate` and equals or occurs before `endDate`.

<TestFile name="toBeBetween">
  {`test('passes when input is in given date range', () => {
 expect(new Date('05/01/2019')).toBeBetween(new Date('01/01/2019'), new Date('10/01/2019'));
 expect(new Date('05/01/2019')).toBeBetween(new Date('05/01/2019'), new Date('10/01/2019'));
 expect(new Date('01/01/2019')).not.toBeBetween(new Date('05/01/2019'), new Date('10/01/2019'));
});`}
</TestFile>
